package manager;

import java.util.ArrayList;

import org.apache.mina.core.session.IoSession;

public class MessageManager {
	private static MessageManager m = new MessageManager();
	public static MessageManager share()
	{
		return m;
	}
	
	// 发送单人消息
	public static void sendSimpleMessage(String account,String msg)
	{
		IoSession ios = DefaultSessionManager.share().getSession(account);
		if (ios != null && ios.isConnected()) {
			ios.write(msg);
		}
	}
	
	//发送多人消息
	public static void sendGroupMessage(ArrayList<String> group,String msg)
	{
		for(String account:group)
		{
			sendSimpleMessage(account, msg);
		}
	}
	
	// 广播
	public static void broadcast(String msg)
	{
		for(IoSession ios:DefaultSessionManager.share().getSessions())
		{
			ios.write(msg);
		}
	}
	
	
}
